package com.zjitc.backend_shop.pojo.po;

import com.alibaba.fastjson.annotation.JSONField;
import com.zjitc.backend_shop.pojo.Admin;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/*
    @author： 尤安托
    @date： 2025/4/22 10:14
*/
@Data
@NoArgsConstructor
public class LoginUser implements UserDetails {
    private List<String> list;
    private Admin admin;

    public LoginUser(Admin admin,List<String> list) {
        this.admin = admin;
        this.list = list;
    }
    @JSONField(serialize = false)
    List<SimpleGrantedAuthority> authorities;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if(authorities!=null){
            return authorities;
        }
        authorities=new ArrayList<>();
        for (String item : list) {
            authorities.add(new SimpleGrantedAuthority(item));
        }
        list.forEach(s->{});
        return authorities;
    }

    @Override
    public String getPassword() {
        return admin.getPassword();
    }

    @Override
    public String getUsername() {
        return admin.getUsername();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

//    @Override
//    public boolean isAccountNonLocked() {
//        return UserDetails.super.isAccountNonLocked();
//    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
